package com.naiking.core
{
	
	import com.naiking.util.BmpdataUtil;
	
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;

	/**
	 * 
	 * @author naiking
	 * 
	 */	
	public class SwfLoader
	{
		private static var _sigLoader:Loader;
		/**
		 *单线程加载 
		 * @param url
		 * @param onComplete
		 * 
		 */		
		public static function getSwfBmpdtBySignal(url:String,onComplete:Function):void
		{
			if(!_sigLoader)
			{
				_sigLoader=new Loader();
				_sigLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, 
					function(e:IOErrorEvent):void{
						trace(e.toString());
					}
				);
				_sigLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{
					trace("loaded");
					//ld.removeEventListener(Event.COMPLETE,arguments.callee);
					var frms:Vector.<BitmapData>;
					frms=BmpdataUtil.getMovieClipSheet(_sigLoader.content as MovieClip);
					onComplete(frms);
					_sigLoader.unloadAndStop(true);
					//ld=null;
				});
				//var ldrContext:LoaderContext = new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain));
			}
			var rq:URLRequest=new URLRequest(url);
			_sigLoader.load(rq);
		}
		public static function getMcBySignal(url:String,onComplete):void
		{
			if(!_sigLoader)
			{
				_sigLoader=new Loader();
				_sigLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, 
					function(e:IOErrorEvent):void{
						trace(e.toString());
					}
				);
				_sigLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{
					trace("loaded");
					
					onComplete(_sigLoader.content as MovieClip);
					_sigLoader.unloadAndStop(true);
					//ld=null;
				});
				//var ldrContext:LoaderContext = new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain));
			}
			var rq:URLRequest=new URLRequest(url);
			_sigLoader.load(rq);
		}
		public function disposeLoadSignal():void
		{
			_sigLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,arguments.callee);
			_sigLoader=null;
		}
		public function SwfLoader()
		{
		}
	}
}